/**
 *  Copyright 2010 Kyle O'Connor, Justin Arling, Mike Mercieca
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package edu.drexel.sd0910.ece01.aqmon;

import javax.swing.SwingUtilities;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import edu.drexel.sd0910.ece01.aqmon.gui.MainController;
import edu.drexel.sd0910.ece01.aqmon.gui.MainModel;
import edu.drexel.sd0910.ece01.aqmon.gui.MainView;

/**
 * 
 * Main class for the Air Quality Monitoring System. This will be the main app
 * running to collect, calculate, store and publish the data on the base station
 * node (Netbook PC). This app will consist of a GUI receiving data from all
 * nodes, running calculations based on algorithms for air quality conversion
 * and either store this data locally or publish it to the web.
 * 
 * @author Kyle O'Connor
 * 
 * @version 2.0
 * 
 */
public class AQSystem {

	private final static Logger log = Logger.getLogger(AQSystem.class);

	public static void main(String[] args) {
		PropertyConfigurator.configure("log4j.properties");
		
		if (args.length != 1) {
			log.fatal("Usage: AQSystem <config file>");
			System.exit(1);
		}

		log.info("Drexel University - Senior Design 2009-2010");
		log.info("Team ECE-01");
		log.info("");
		log.info("Starting Air Quality System...");
		log.info("");

		log.debug("Loading GUI...");
		MainModel model = new MainModel(args[0]);
		final MainView view = new MainView(model);
		@SuppressWarnings("unused")
		MainController controller = new MainController(model, view);
		model.addObserver(view); // register view to listen to model updates
		
		//execute GUI code safely
	    SwingUtilities.invokeLater(new Runnable() {
	        public void run() {
	    		view.setVisible(true);
	    		// center on screen (needs to be after setVisible)
	    		//view.setLocationRelativeTo(null);
	        }
	      });
	    
		log.debug("GUI Displayed");
	}

}
